package com.hps.demo.config;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author heps
 * @since 2020/7/16 11:10
 */
@Configuration
public class ExecutorConfig {

  @Bean(name = "bizExecutor")
  public Executor bizExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("biz-executor-");
    executor.setCorePoolSize(8);
    executor.setMaxPoolSize(16);
    executor.setQueueCapacity(32);
    executor.setRejectedExecutionHandler(new CallerRunsPolicy());
    executor.setKeepAliveSeconds(30);
    executor.setDaemon(true);
    return executor;
  }
}
